﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Projektet.View
{
    class SplitterParticle
    {
        int m_seed;
        Texture2D _splitterTexture;
        Random rand;
        Vector2 _startPosition;
        Vector2 _splitterPosition;
        Vector2 _velocity;
        Vector2 _acceleration;
        int _diameter;
        float _decay = 1f;

        public SplitterParticle(Vector2 startingPosition, int seed, Texture2D texture)
        {
            m_seed = seed;
            rand = new Random(seed);
            _splitterTexture = texture;
            _diameter = 1;
            _startPosition = startingPosition;
            _splitterPosition = new Vector2(_startPosition.X, _startPosition.Y);

            _velocity = new Vector2((float)(rand.NextDouble() * 0.02 - 0.01), (float)(rand.NextDouble() * 0.1 - 0.2));
            _velocity.Normalize();

            _acceleration = new Vector2(0f, 3f);

            float min = 0.015f;
            float max = 0.03f;

            float particleSpeed = min + ((float)(rand.NextDouble()) * (max - min));

            _acceleration *= particleSpeed;
        }

        internal void Draw(SpriteBatch spritebatch)
        {
            _decay -= 0.01f;
            _splitterPosition += _velocity;
            Color fade = new Color(_decay, _decay, _decay, _decay);
            _velocity += _acceleration;

            Rectangle splitterRectangle = Camera.GetVisualRectangle(new Rectangle((int)_splitterPosition.X, (int)_splitterPosition.Y, _diameter, _diameter));
            
            spritebatch.Draw(_splitterTexture, splitterRectangle, null, fade, _decay, new Vector2(), SpriteEffects.None, 0.1f);
        }
    }
}
